package br.ufrn.engcomp.dao;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import br.ufrn.engcomp.arq.Papeis;
import br.ufrn.engcomp.domain.User;

@Repository
public class UserDAO extends GenericDAOHibernate {

    public boolean existeLogin(String login) {
	Criteria c = getCriteria(User.class);
	c.add(Restrictions.eq("login", login));
	c.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
	return !c.list().isEmpty();
    }

    public boolean existeAdmin() {
	Criteria c = getCriteria(User.class);
	c.add(Restrictions.eq("role", Papeis.ADMIN));
	return !c.list().isEmpty();
    }

}
